From 4c80300499d783333e24331f7c5a368ecf24c3bf Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Wed, 6 Jun 2012 20:04:03 +0200 Subject: [PATCH] Prefer console.error over console.log for exception logging Follows-up: * r112453: 268e016f08c5de6a68c25abf182d0115a6f131d5 * r88392 : bdac16978c6827bb5d8709071ee8afb99707ec3e This way it works in both the Chrome Dev Tools and Firebug in Firefox. Change-Id: If8b3c2747882c1e21e413f062e4c89c34144c64b --- resources/mediawiki/mediawiki.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/resources/mediawiki/mediawiki.js b/resources/mediawiki/mediawiki.js index 66309bb698..793cf225ed 100644 --- a/resources/mediawiki/mediawiki.js +++ b/resources/mediawiki/mediawiki.js @@ -626,17 +626,21 @@ var mw = ( function ( $, undefined ) { /** * Log a message to window.console, if possible. Useful to force logging of some - * errors that are otherwise hard to detect, even if mw.log is not available. (I.e., - * this logs also if not in debug mode.) + * errors that are otherwise hard to detect (I.e., this logs also in production mode). + * Gets console references in each invocation, so that delayed debugging tools work + * fine. No need for optimization here, which would only result in losing logs. * - * @param msg String text for the log entry - * @param e Error [optional] to also log. + * @param msg String text for the log entry. + * @param e Error [optional] to also log. */ function log( msg, e ) { - if ( window.console && typeof window.console.log === 'function' ) { + var console = window.console; + if ( console && console.log ) { console.log( msg ); + // console.error triggers the proper handling of exception objects in + // consoles that support it. Fallback to passing as plain object to log(). if ( e ) { - console.log( e ); + (console.error || console.log).call( console, e ); } } } -- 2.20.1